package com.easybuy.dao.impl;

import com.easybuy.dao.UserDao;
import com.easybuy.entity.User;
import com.easybuy.utils.BaseDao;

import java.sql.SQLException;
import java.util.List;

public class UserDaoImpl extends BaseDao implements UserDao {

	public List<User> findUsers() {
		return null;
	}

//	@Override
//	public List<User> findUserByName(String loginUser) {
//		String sql="select easybuy_user.id,userName,address,email,mobile from easybuy_user inner join easybuy_user_address on easybuy_user.id=easybuy_user_address.userId where easybuy_user.loginName=?";
//		List<User> users=new ArrayList<User>();
////		User user=null;
//		try {
//			prestmt=this.connectMysql().prepareStatement(sql);
//			prestmt.setString(1, loginUser);
//			rs=prestmt.executeQuery();
//			while(rs.next()){
//				users.add(new User(rs.getInt("easybuy_user.id"), rs.getString("userName"), rs.getString("email"), rs.getString("mobile"), rs.getString("address")));
//			}
//			
//			
//		} catch (SQLException e) {
//			e.printStackTrace();
//		}
//		return users;
//	}

	public User findUserBylogin(String loginName) {
		User user=null;
		String sql="select * from easybuy_user where easybuy_user.loginName=?";
		
		try {
			prestmt=this.connectMysql().prepareStatement(sql);
			prestmt.setString(1, loginName);
			rs=prestmt.executeQuery();
			while(rs.next()){
				user=new User(rs.getInt("id"), rs.getString("loginName"), rs.getString("userName"), rs.getString("password"), rs.getInt("sex"), rs.getString("identityCode"), rs.getString("email"), rs.getString("mobile"), rs.getInt("type"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return user;
	}

}
